package com.bjpowernode.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bjpowernode.common.constant.Constant;
import com.bjpowernode.entity.TClueRemark;
import com.bjpowernode.entity.query.ClueRemarkQuery;
import com.bjpowernode.mapper.TClueRemarkMapper;
import com.bjpowernode.service.ClueRemarkService;
import com.bjpowernode.util.LoginInfoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ClueRemarkServiceImpl implements ClueRemarkService {
    private final TClueRemarkMapper clueRemarkMapper;


    @Override
    public int saveClueRemark(ClueRemarkQuery clueRemarkQuery) {
        TClueRemark clueRemark = new TClueRemark();
        BeanUtil.copyProperties(clueRemarkQuery, clueRemark);
        clueRemark.setCreateTime(new Date());
        clueRemark.setCreateBy(LoginInfoUtil.getCurrentLoginUser().getId());
        return clueRemarkMapper.insert(clueRemark);
    }

    @Override
    public PageInfo<TClueRemark> getClueRemarks(Integer current, Integer clueId) {
        PageHelper.startPage(current, Constant.PAGE_SIZE);
        List<TClueRemark> list = clueRemarkMapper.getClueRemarksByPage(clueId);
        return new PageInfo<TClueRemark>(list);
    }
}
